import axios from 'axios'

const http = axios.create({
    baseURL: '/api',
    timeout: 10000
})

http.interceptors.request.use(config=>{

    //将token传到后端
    let token = localStorage.getItem('token');
    if(token){
        config.headers['authorization'] = 'Bearer ' + token;
    }

    return config;
},err=>{
    return Promise.reject(err);
})











//axios请求时拦截
// http.interceptors.request.use(config=>{
//     const token = localStorage.getItem('token');
//     if(token) {
//         config.headers['Authorization'] = 'Bearer ' + token;
//     }
//     //添加token令牌
//     return config;
// },err=>{
//     return Promise.reject(err);
// })

//axios响应时候拦截
http.interceptors.response.use(data=>{return data},err=>{return Promise.reject(err);})

export default http